# 接口联调测试
import requests


class WorkFlowForgetPasswordTestV1:
    # 用户注册接口测试
    def register_test(self):
        url = "http://129.211.129.101:9006/user/register.do"
        user_info = {}
        # 正确的用户数据
        user_info = {
            "username": "lllljl",
            "password": "123456",
            "email": "lllljjj@qq.com",
            "phone": "13555555556",
            "question": "喜欢看的书",
            "answer": "阿衰"
        }
        # 发送请求
        res = requests.post(url, data=user_info).text
        r = res.find("注册成功")
        if r > 0:
            print("注册接口测试通过")
        else:
            print("注册接口测试不通过")

    # 用户登录
    def login_test(self):
        url = "http://129.211.129.101:9006/user/login.do"
        user_info = {}
        # 正确的用户数据
        user_info = {
            "username": "lllljl",
            "password": "123456"
        }
        # 发送请求
        res = requests.post(url, data=user_info).text
        r = res.find("登录成功")
        if r > 0:
            print("登录接口测试通过")
        else:
            print("登录接口测试不通过")

    # 忘记密码
    def forget_password_test(self):
        url = "http://129.211.129.101:9006/user/forget_get_question.do"
        user_info = {}
        # 正确的用户数据
        user_info = {
            "username": "lllljl"
        }
        # 发送请求
        res = requests.post(url, data=user_info).text
        r = res.find("最喜欢的书")
        if r > 0:
            print("忘记密码接口测试通过")
        else:
            print("忘记密码接口测试不通过")

    # 提交密保
    def security_submit_test(self):
        url = "http://129.211.129.101:9006/user/forget_check_answer.do"
        user_info = {}
        # 正确的用户数据
        user_info = {
            "username": "lllljl",
            "question": "喜欢看的书",
            "answer": "阿衰"
        }
        # 发送请求
        res = requests.post(url, data=user_info).text
        print(res)
        print(type(res))
        # 转换为dict类型
        dic = {}
        dic = eval(res)
        token = dic["data"]
        r = res.find("data")
        if r > 0:
            print("提交密保接口测试通过")
        else:
            print("提交密保接口测试不通过")

        return token

    # 修改密码
    def modify_password_test(self, token):
        url = "http://129.211.129.101:9006/user/forget_reset_password.do"
        user_info = {}
        # 正确的用户数据
        user_info = {
            "username": "lllljl",
            "passwordNew": "111111",
            "forgetToken": token
        }
        # 发送请求
        res = requests.post(url, data=user_info).text
        r = res.find("修改密码成功")
        if r > 0:
            print("修改密码接口测试通过")
        else:
            print("修改密码接口测试不通过")


if __name__ == '__main__':
    # WorkFlowForgetPasswordTest().register_test()
    # WorkFlowForgetPasswordTest().login_test()
    # WorkFlowForgetPasswordTest().forget_password_test()
    token = WorkFlowForgetPasswordTestV1().security_submit_test()
    WorkFlowForgetPasswordTestV1().modify_password_test(token)
